# -*- Mode: Python -*- vi:si:et:sw=4:sts=4:ts=4:syntax=python
import os
from cerbero.utils.shell import which
from cerbero.tools.libtool import LibtoolLibrary

class Recipe(recipe.Recipe):
    name = 'glib-networking'
    version = '2.62.3'
    licenses = [{License.LGPLv2Plus: None, License.Misc: ['LICENSE_EXCEPTION']}]
    stype = SourceType.TARBALL
    btype = BuildType.MESON
    url = 'gnome://'
    tarball_checksum = '8ca1f86f23a76b5c7640624f7d5490705c78e81375e1741c9a1c41ce7f8f7ff7'
    meson_options = {'ca_certificates_path': '', 'libproxy_support': 'false',
                     'gnome_proxy_support': 'false', 'pkcs11_support': 'false',
                     'gnutls': 'disabled', 'openssl': 'enabled',
                     # Also build static modules on all platforms
                     'static_modules': 'true'}
    deps = ['glib']
    # openssl on Linux
    use_system_libs = True

    files_misc = ['lib/gio/modules/libgioopenssl%(mext)s']
    files_lang = ['glib-networking']
    files_devel = ['lib/gio/modules/libgioopenssl.a']

    def prepare(self):
        # Pick system openssl if on Linux and not cross-compiling
        if self.config.target_platform != Platform.LINUX or self.config.cross_compiling():
            self.deps.append('openssl')

    def post_install(self):
        # Meson does not generate la files
        LibtoolLibrary('gioopenssl', None, None, None,
                os.path.join(self.config.libdir, 'gio', 'modules'),
                self.config.target_platform, deps=['ssl', 'crypto']).save()
        super().post_install()
